from pyspark import SparkContext,SparkConf
import os
os.environ["PYSPARK_PYTHON"] = "D:/Soft/Python/Python310/python.exe"

if __name__ == '__main__':
    conf = SparkConf().setMaster("local[*]").setAppName("test")
    sc = SparkContext(conf=conf)

    # filter测试
    print(sc.parallelize([1,2,3,4,5,6,7]).filter(lambda ele:ele%2==1).collect())

    # distinct测试
    print(sc.parallelize([1,2,2,3,4,2,3,5,2]).distinct().collect())

    # sortBy测试
    print(sc.parallelize([("a",11,"你好"),("b",6,"张三"),("c",9,"haha")]).sortBy(lambda ele:ele[2],ascending=True,numPartitions=1).collect())
    print(sc.parallelize([('itcast', 4), ('python', 6), ('itheima', 7), ('spark', 4), ('pyspark', 3)]).sortBy(lambda ele:ele[1],ascending=False,numPartitions=1).collect())

    sc.stop()
